#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
    char file[32] = "/tmp/test.img";
    int fd = open(file, O_RDONLY);
    if (fd < 0)
    {
        perror("open");
        return -1;
    }

    // char buf[4096];
    // uint8_t* buf = malloc(4096);
    int len;
    int count = 0;
    while (1)
    {
        uint8_t* buf = malloc(4096);
        if (buf == NULL){
            perror("malloc failed: ");
            break;
        }
        memset(buf, 0, 4096);

        len = read(fd, buf, 4096);
        if (len <= 0)
            break;
        count ++;
        // printf("read %d bytes\n", len);
        free(buf);

        if (count == 131070)
        {
            printf("输入any按键继续\n");
            fgets((char *)buf, 4096, stdin);
        }
    }
    printf("read %d times\n", count);
}